package com.ifreeee.practice.pc.bilibili;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取哔哩哔哩收藏夹所有 视频 Json
 */
public class GetAllJsonUtils {

    /**
     * 收藏夹 url
     * https://space.bilibili.com/106592056/favlist?fid=1872830356&ftype=create
     * https://api.bilibili.com/x/v3/fav/resource/list?media_id=1872830356&pn=1&ps=20&keyword=&order=mtime&type=0&tid=0&platform=web&jsonp=jsonp
     */
    private static final String URL = "https://api.bilibili.com/x/v3/fav/resource/list?media_id=1872830356&pn=1&ps=20&keyword=&order=mtime&type=0&tid=0&platform=web&jsonp=jsonp";

    private static final String PAGE_INDEX = "pn";

    private static final String EQU = "=";

    private static final String URL_INIT_INDEX = "1";

    /**
     * 字符集
     */
    private static final String CHARSET = "utf-8";

    public static List<String> getAllJson () {
        int i = 1;
        List<String> allJson = new ArrayList<>();
        String currJson = null;
        String currUrl = null;
        do {
            currUrl = URL.replaceAll(PAGE_INDEX + EQU + URL_INIT_INDEX, PAGE_INDEX + EQU + i ++);
            String resp = HttpUtil.sendGet(currUrl, CHARSET);
            currJson = JsonPropUtils.getJsonObj(resp);
            allJson.add(currJson);
        } while (StringUtils.isNotBlank(currJson));
        allJson.remove(allJson.size() - 1);
        return allJson;
    }

    public static void main(String[] args) {
        List<String> allJson = getAllJson();
        System.out.println(allJson);
    }


}
